$.extend({
	/**
	 * Create DialogBox by ID
	 * 
	 * @param {
	 *            String } elementID
	 */
	getOrCreateDialog : function(id) {

		$box = $('#' + id);
		if (!$box.length) {
			$box = $('<div id="' + id + '"><p></p></div>').hide().appendTo(
					'body');
		}
		return $box;
	}
});
/**
 * Override javascript alert() and wrap it into a jQuery-UI Dialog box
 * 
 * @depends $.getOrCreateDialog
 * 
 * @param {
 *            String } the alert message
 * @param {
 *            Object } jQuery Dialog box options
 */
function jalert(message, options) {

	var defaults = {
		modal : true,
		resizable : false,
		buttons : {
			"Подтвердить" : function() {
				$(this).dialog('close');
			}
		},
		minHeight : 50,
		dialogClass : 'modal-shadow'
	};

	$alert = $.getOrCreateDialog('alert');
	
	$("p", $alert).html(message);
	
	$alert.dialog($.extend({}, defaults, options));
}

/**
 * Override javascript confirm() and wrap it into a jQuery-UI Dialog box
 *
 * @depends $.getOrCreateDialog
 *
 * @param { String } the alert message
 * @param { String/Object } the confirm callback
 * @param { Object } jQuery Dialog box options
 */
function jconfirm(message, callback, options) {

	var defaults = {
		modal : true,
		resizable : false,
		buttons : {
			Ok : function() {
				$(this).dialog('close');
				return (typeof callback == 'string') ? window.location.href = callback
						: callback();
			},
			Cancel : function() {
				$(this).dialog('close');
				return false;
			}
		},
		minHeight : 50,
		dialogClass : 'modal-shadow'
	};

	$confirm = $.getOrCreateDialog('confirm');
	
	$("p", $confirm).html(message);
	
	$confirm.dialog($.extend({}, defaults, options));
}